//package com.openx.amqp;
//
//import org.springframework.amqp.AmqpException;
//import org.springframework.amqp.core.Binding;
//import org.springframework.amqp.core.Queue;
//import org.springframework.amqp.core.TopicExchange;
//import org.springframework.amqp.rabbit.connection.ConnectionFactory;
//import org.springframework.amqp.rabbit.core.RabbitAdmin;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.amqp.rabbit.support.CorrelationData;
//import org.springframework.context.ApplicationContext;
//
//public class XRabbitTemplate extends RabbitTemplate {
//    private RabbitAdmin rabbitAdmin;
//    private ApplicationContext applicationContext;
//    
//    public XRabbitTemplate() {
//        super();
//    }
//    
//    public XRabbitTemplate(ConnectionFactory connectionFactory) {
//        super(connectionFactory);
//    }
//    public XRabbitTemplate(ConnectionFactory connectionFactory, ApplicationContext applicationContext) {
//        super(connectionFactory);
//        this.applicationContext = applicationContext;
//    }
//    
//    public XRabbitTemplate(RabbitAdmin rabbitAdmin) {
//        super();
//        this.rabbitAdmin = rabbitAdmin;
//    }
//    
//    public XRabbitTemplate(ConnectionFactory connectionFactory, RabbitAdmin rabbitAdmin) {
//        super(connectionFactory);
//        this.rabbitAdmin = rabbitAdmin;
//    }
//    public XRabbitTemplate(ConnectionFactory connectionFactory, RabbitAdmin rabbitAdmin, ApplicationContext applicationContext) {
//        super(connectionFactory);
//        this.rabbitAdmin = rabbitAdmin;
//        this.applicationContext = applicationContext;
//    }
//    
//    public void convertAndSend(String exchange, String routingKey, Object object, CorrelationData correlationData)
//        throws AmqpException {
//        System.out.println("exchange="+exchange+",routingKey="+routingKey+",object="+object+",correlationData="+correlationData);
//        if(exchange == null || "".equals(exchange.trim())) {
//            // 直接发queue
//            Object obj = applicationContext.getAutowireCapableBeanFactory().getBean("queue."+routingKey);
//            if(obj == null) {
//                Queue queue = new Queue(routingKey);
//                rabbitAdmin.declareQueue(queue);
//            }
//        } else {
//            rabbitAdmin.declareExchange(new TopicExchange(exchange));
////            rabbitAdmin.declareBinding(new Binding(destination, destinationType, exchange, routingKey, arguments));
//            if(routingKey == null || "".equals(routingKey.trim())) {
//                // 发fanout（广播）
//            
//            } else {
//                // 发topic，组播
//                
//            }
//        }
//        this.setRoutingKey(routingKey);
//        this.setExchange(exchange);
//        send(exchange, routingKey, convertMessageIfNecessary(object), correlationData);
//    }
//}
